<template>
    <div>
        <input type="text" placeholder="请输入" v-model="name"/>
        <button @click="add">添加</button>
        <h3 style="color:green;">上方组件的sum数：{{sum}}</h3>
        <ul>
            <li v-for="p in personList" :key="p.id">{{p.name}}</li>
        </ul>
    </div>
</template>

<script>
    export default {
        name: "Person",
        data(){
            return {
                name:''
            }
        },
        computed:{
            personList(){
                return this.$store.state.personList;
            },
            sum(){
                return this.$store.state.sum;
            }
        },
        methods:{
            add(){
                const personObj={id:2,name:this.name}
                this.$store.commit('ADD_PERSON',personObj)
            }
        }
    }
</script>

<style scoped>

</style>